from appium.webdriver.common.appiumby import  AppiumBy
from selenium.webdriver.support.ui import WebDriverWait
import os
from base.base import Base



class LoginPage:
       def __init__(self,driver):
              self.personal_homepage_locator=(AppiumBy.XPATH,
"//android.widget.FrameLayout[@resource-id='android:id/content']/android.widget.FrameLayout/android.view.View/android.view.View/android.view.View/android.view.View[1]/android.view.View/android.view.View/android.widget.ImageView[1]")#个人页面元素


              self.subscription_management_locator=(AppiumBy.XPATH,
"//android.widget.ImageView[@content-desc='订阅管理']")#订阅管理元素


              self.logout_button_locator = (AppiumBy.XPATH,
"//android.widget.ImageView[@content-desc='退出登录']")#登出按钮


              self.confirm_logout_locator = (AppiumBy.XPATH,
"//android.widget.Button[@content-desc='退出登录']")#确定登出按钮


              self.user_account_number_locator = (AppiumBy.XPATH,
"//android.widget.FrameLayout[@resource-id='android:id/content']/android.widget.FrameLayout/android.view.View/android.view.View/android.view.View/android.view.View[2]/android.widget.ImageView[2]")  # 账号输入框


              self.user_pwd_number_locator = (AppiumBy.CLASS_NAME,
"android.widget.EditText")  # 密码输入框


              self.login_button_locator = (AppiumBy.XPATH,
"//android.widget.Button[@content-desc='立即登录']")  # 登录按钮


              self.privacy_policy_locator = (AppiumBy.XPATH,
"// android.widget.CheckBox")  # 隐私政策按钮


              self.google_login_button_locator=(AppiumBy.XPATH,
"//android.widget.FrameLayout[@resource-id='android:id/content']/android.widget.FrameLayout/android.view.View/android.view.View/android.view.View/android.view.View[2]/android.widget.ImageView[3]")#谷歌登录按钮


              self.confirm_google_login_locator = (AppiumBy.XPATH,
"(//android.widget.LinearLayout[@resource-id='com.google.android.gms:id/container'])[1]/android.widget.LinearLayout")#确定谷歌登录按钮


       # 接受传入的driver
              self.driver = driver


       # 生成一个显示等待对象
              self.wait = WebDriverWait(driver, 5)


       # #调试语句
       #        self.driver=webdriver.Remote(settings.appium_server,settings.desired_caps)


       # 获取当前文件目录和上层目录绝对路径
              cur_dir = os.path.dirname(os.path.abspath(__file__))
              parent_dir = os.path.dirname(cur_dir)

       #实例化base
              self.base = Base(self.driver, self.wait)


       #点击个人页面操作
       def  click_personal_homepage(self) -> None:
             self.base.click_personal_homepage(self.personal_homepage_locator)


       #点击订阅管理操作
       def click_subscription_management(self) -> None:
              self.base.click_subscription_management(self.subscription_management_locator)

       #点击登出按钮
       def click_logout_button(self) -> None:
              self.base.click_logout_button(self.logout_button_locator)


       # 点击确认登出按钮
       def click_confirm_logout(self) -> None:
              self.base.click_confirm_logout(self.confirm_logout_locator)

       #输入账号操作
       def input_user_account_number(self,user) -> None:
              self.base.input_user_account_number(self.user_account_number_locator,user)


       #输入密码操作
       def input_user_pwd(self,pwd) -> None:
              self.base.input_user_pwd(self.user_pwd_number_locator,pwd)


       # 点击隐私政策操作
       def click_privacy_policy(self) -> None:
          self.base.click_privacy_policy(self.privacy_policy_locator)

       #点击登录操作
       def click_login(self) -> None:
          self.base.click_login(self.login_button_locator)

       #点击谷歌按钮
       def click_to_google(self) -> None:
           self.base.click_to_google(self.google_login_button_locator)


       #选择账号确定谷歌登录
       def click_to_confirm_google(self) -> None:
           self.base.click_to_confirm_google(self.confirm_google_login_locator)





# if __name__ == '__main__':
#     # driver = webdriver.Remote(settings.appium_server,settings.desired_caps)
#     # login_page = LoginPage(driver)
#     # login_page.click_Personal_Homepage()
#     # login_page.click_Logout_Button()
#     # login_page.click_Confirm_logout()
#     # login_page.click_Personal_Homepage()
#     # login_page.click_Subscription_Management()
#     # login_page.input_user_account_number("1472768082@qq.com")
#     # login_page.input_user_pwd("Xiongyijie2002")
#     # login_page.click_Privacy_Policy()
#     # login_page.click_Login()

